package com.guducat.collegeWeb.mapper;

import com.guducat.collegeWeb.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HomeMapper {
    // HomeSlide相关方法
    @Results(id = "homeSlideResultMap", value = {
        @Result(property = "id", column = "id", id = true),
        @Result(property = "title", column = "title"),
        @Result(property = "description", column = "description"),
        @Result(property = "imageUrl", column = "image_url"),
        @Result(property = "linkUrl", column = "link_url"),
        @Result(property = "displayOrder", column = "display_order"),
        @Result(property = "isActive", column = "is_active"),
        @Result(property = "createdAt", column = "created_at"),
        @Result(property = "updatedAt", column = "updated_at")
    })
    @Select("SELECT * FROM home_slides ORDER BY display_order ASC")
    List<HomeSlide> getAllHomeSlides();

    @ResultMap("homeSlideResultMap")
    @Select("SELECT * FROM home_slides WHERE is_active = 1 ORDER BY display_order ASC")
    List<HomeSlide> getActiveHomeSlides();

    @ResultMap("homeSlideResultMap")
    @Select("SELECT * FROM home_slides WHERE id = #{id}")
    HomeSlide getHomeSlideById(Integer id);

    @Insert("INSERT INTO home_slides (title, description, image_url, link_url, display_order, is_active, created_at, updated_at) " +
           "VALUES (#{title}, #{description}, #{imageUrl}, #{linkUrl}, #{displayOrder}, #{isActive}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertHomeSlide(HomeSlide homeSlide);

    @Update("UPDATE home_slides SET title = #{title}, description = #{description}, image_url = #{imageUrl}, " +
           "link_url = #{linkUrl}, display_order = #{displayOrder}, is_active = #{isActive}, updated_at = NOW() " +
           "WHERE id = #{id}")
    int updateHomeSlide(HomeSlide homeSlide);

    @Delete("DELETE FROM home_slides WHERE id = #{id}")
    int deleteHomeSlide(Integer id);

    // CampusHighlight相关方法
    @Results(id = "campusHighlightResultMap", value = {
        @Result(property = "id", column = "id", id = true),
        @Result(property = "title", column = "title"),
        @Result(property = "category", column = "category"),
        @Result(property = "imageUrl", column = "image_url"),
        @Result(property = "date", column = "date"),
        @Result(property = "linkUrl", column = "link_url"),
        @Result(property = "displayOrder", column = "display_order"),
        @Result(property = "isActive", column = "is_active"),
        @Result(property = "createdAt", column = "created_at"),
        @Result(property = "updatedAt", column = "updated_at")
    })
    @Select("SELECT * FROM campus_highlights ORDER BY display_order ASC")
    List<CampusHighlight> getAllCampusHighlights();

    @ResultMap("campusHighlightResultMap")
    @Select("SELECT * FROM campus_highlights WHERE is_active = 1 ORDER BY display_order ASC")
    List<CampusHighlight> getActiveCampusHighlights();

    @ResultMap("campusHighlightResultMap")
    @Select("SELECT * FROM campus_highlights WHERE id = #{id}")
    CampusHighlight getCampusHighlightById(Integer id);

    @Insert("INSERT INTO campus_highlights (title, category, image_url, date, link_url, display_order, is_active, created_at, updated_at) " +
           "VALUES (#{title}, #{category}, #{imageUrl}, #{date}, #{linkUrl}, #{displayOrder}, #{isActive}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertCampusHighlight(CampusHighlight campusHighlight);

    @Update("UPDATE campus_highlights SET title = #{title}, category = #{category}, image_url = #{imageUrl}, " +
           "date = #{date}, link_url = #{linkUrl}, display_order = #{displayOrder}, is_active = #{isActive}, updated_at = NOW() " +
           "WHERE id = #{id}")
    int updateCampusHighlight(CampusHighlight campusHighlight);

    @Delete("DELETE FROM campus_highlights WHERE id = #{id}")
    int deleteCampusHighlight(Integer id);

    // AcademicResearch相关方法
    @Results(id = "academicResearchMap", value = {
            @Result(property = "id", column = "id", id = true),
            @Result(property = "title", column = "title"),
            @Result(property = "description", column = "description"),
            @Result(property = "imageUrl", column = "image_url"),
            @Result(property = "linkUrl", column = "link_url"),
            @Result(property = "isActive", column = "is_active")
    })
    @Select("SELECT * FROM academic_research WHERE is_active = 1")
    List<AcademicResearch> getActiveAcademicResearches();

    @Insert("INSERT INTO academic_research (title, description, image_url, link_url, is_active) " +
            "VALUES (#{title}, #{description}, #{imageUrl}, #{linkUrl}, #{isActive})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertAcademicResearch(AcademicResearch research);

    @Update("UPDATE academic_research SET title=#{title}, description=#{description}, " +
            "image_url=#{imageUrl}, link_url=#{linkUrl}, is_active=#{isActive} WHERE id=#{id}")
    int updateAcademicResearch(AcademicResearch research);

    @Delete("DELETE FROM academic_research WHERE id=#{id}")
    int deleteAcademicResearch(long id);

    // MiddleSlide相关方法
    @Results(id = "middleSlideResultMap", value = {
        @Result(property = "id", column = "id", id = true),
        @Result(property = "title", column = "title"),
        @Result(property = "subtitle", column = "subtitle"),
        @Result(property = "content", column = "content"),
        @Result(property = "backgroundImage", column = "background_image"),
        @Result(property = "displayOrder", column = "display_order"),
        @Result(property = "isActive", column = "is_active"),
        @Result(property = "createdAt", column = "created_at"),
        @Result(property = "updatedAt", column = "updated_at")
    })
    @Select("SELECT * FROM middle_slides ORDER BY display_order ASC")
    List<MiddleSlide> getAllMiddleSlides();

    @ResultMap("middleSlideResultMap")
    @Select("SELECT * FROM middle_slides WHERE is_active = 1 ORDER BY display_order ASC")
    List<MiddleSlide> getActiveMiddleSlides();

    @ResultMap("middleSlideResultMap")
    @Select("SELECT * FROM middle_slides WHERE id = #{id}")
    MiddleSlide getMiddleSlideById(Integer id);

    @Insert("INSERT INTO middle_slides (title, subtitle, content, background_image, display_order, is_active, created_at, updated_at) " +
           "VALUES (#{title}, #{subtitle}, #{content}, #{backgroundImage}, #{displayOrder}, #{isActive}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertMiddleSlide(MiddleSlide middleSlide);

    @Update("UPDATE middle_slides SET title = #{title}, subtitle = #{subtitle}, content = #{content}, " +
           "background_image = #{backgroundImage}, display_order = #{displayOrder}, is_active = #{isActive}, updated_at = NOW() " +
           "WHERE id = #{id}")
    int updateMiddleSlide(MiddleSlide middleSlide);

    @Delete("DELETE FROM middle_slides WHERE id = #{id}")
    int deleteMiddleSlide(Integer id);

    // HeroSection相关方法
    @Results(id = "heroSectionResultMap", value = {
        @Result(property = "id", column = "id", id = true),
        @Result(property = "mainTitle", column = "main_title"),
        @Result(property = "highlightText", column = "highlight_text"),
        @Result(property = "subTitle", column = "sub_title"),
        @Result(property = "button1Text", column = "button1_text"),
        @Result(property = "button1Link", column = "button1_link"),
        @Result(property = "button2Text", column = "button2_text"),
        @Result(property = "button2Link", column = "button2_link"),
        @Result(property = "isActive", column = "is_active"),
        @Result(property = "createdAt", column = "created_at"),
        @Result(property = "updatedAt", column = "updated_at")
    })
    @Select("SELECT * FROM hero_section")
    List<HeroSection> getAllHeroSections();

    @ResultMap("heroSectionResultMap")
    @Select("SELECT * FROM hero_section WHERE is_active = 1 LIMIT 1")
    HeroSection getActiveHeroSection();

    @ResultMap("heroSectionResultMap")
    @Select("SELECT * FROM hero_section WHERE id = #{id}")
    HeroSection getHeroSectionById(Integer id);

    @Insert("INSERT INTO hero_section (main_title, highlight_text, sub_title, button1_text, button1_link, " +
           "button2_text, button2_link, is_active, created_at, updated_at) " +
           "VALUES (#{mainTitle}, #{highlightText}, #{subTitle}, #{button1Text}, #{button1Link}, " +
           "#{button2Text}, #{button2Link}, #{isActive}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertHeroSection(HeroSection heroSection);

    @Update("UPDATE hero_section SET main_title = #{mainTitle}, highlight_text = #{highlightText}, " +
           "sub_title = #{subTitle}, button1_text = #{button1Text}, button1_link = #{button1Link}, " +
           "button2_text = #{button2Text}, button2_link = #{button2Link}, is_active = #{isActive}, updated_at = NOW() " +
           "WHERE id = #{id}")
    int updateHeroSection(HeroSection heroSection);

    @Delete("DELETE FROM hero_section WHERE id = #{id}")
    int deleteHeroSection(Integer id);

    // HeroOption相关方法
    @Results(id = "heroOptionResultMap", value = {
        @Result(property = "id", column = "id", id = true),
        @Result(property = "title", column = "title"),
        @Result(property = "description", column = "description"),
        @Result(property = "imageUrl", column = "image_url"),
        @Result(property = "displayOrder", column = "display_order"),
        @Result(property = "isActive", column = "is_active"),
        @Result(property = "createdAt", column = "created_at"),
        @Result(property = "updatedAt", column = "updated_at")
    })
    @Select("SELECT * FROM hero_options ORDER BY display_order ASC")
    List<HeroOption> getAllHeroOptions();

    @ResultMap("heroOptionResultMap")
    @Select("SELECT * FROM hero_options WHERE is_active = 1 ORDER BY display_order ASC")
    List<HeroOption> getActiveHeroOptions();

    @ResultMap("heroOptionResultMap")
    @Select("SELECT * FROM hero_options WHERE id = #{id}")
    HeroOption getHeroOptionById(Integer id);

    @Insert("INSERT INTO hero_options (title, description, image_url, display_order, is_active, created_at, updated_at) " +
           "VALUES (#{title}, #{description}, #{imageUrl}, #{displayOrder}, #{isActive}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertHeroOption(HeroOption heroOption);

    @Update("UPDATE hero_options SET title = #{title}, description = #{description}, image_url = #{imageUrl}, " +
           "display_order = #{displayOrder}, is_active = #{isActive}, updated_at = NOW() " +
           "WHERE id = #{id}")
    int updateHeroOption(HeroOption heroOption);

    @Delete("DELETE FROM hero_options WHERE id = #{id}")
    int deleteHeroOption(Integer id);

    // HeroStat相关方法
    @Results(id = "heroStatResultMap", value = {
        @Result(property = "id", column = "id", id = true),
        @Result(property = "number", column = "number"),
        @Result(property = "suffix", column = "suffix"),
        @Result(property = "label", column = "label"),
        @Result(property = "displayOrder", column = "display_order"),
        @Result(property = "isActive", column = "is_active"),
        @Result(property = "createdAt", column = "created_at"),
        @Result(property = "updatedAt", column = "updated_at")
    })
    @Select("SELECT * FROM hero_stats ORDER BY display_order ASC")
    List<HeroStat> getAllHeroStats();

    @ResultMap("heroStatResultMap")
    @Select("SELECT * FROM hero_stats WHERE is_active = 1 ORDER BY display_order ASC")
    List<HeroStat> getActiveHeroStats();

    @ResultMap("heroStatResultMap")
    @Select("SELECT * FROM hero_stats WHERE id = #{id}")
    HeroStat getHeroStatById(Integer id);

    @Insert("INSERT INTO hero_stats (number, suffix, label, display_order, is_active, created_at, updated_at) " +
           "VALUES (#{number}, #{suffix}, #{label}, #{displayOrder}, #{isActive}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertHeroStat(HeroStat heroStat);

    @Update("UPDATE hero_stats SET number = #{number}, suffix = #{suffix}, label = #{label}, " +
           "display_order = #{displayOrder}, is_active = #{isActive}, updated_at = NOW() " +
           "WHERE id = #{id}")
    int updateHeroStat(HeroStat heroStat);

    @Delete("DELETE FROM hero_stats WHERE id = #{id}")
    int deleteHeroStat(Integer id);
}
